﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Ylh.BLL;
using ExtAspNet;

public partial class Module_CustManger_CustMeet : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Button2.OnClientClick = ActiveWindow.GetHidePostBackReference();

        if (!IsPostBack)
        {
            LoadData(Request.QueryString["CustID"].ToString());
        }

        if (Request.QueryString["enable"] != null)
        {
            MetingTime.Readonly = Accompany.Readonly = Remark.Readonly = true;
            btnSave.Hidden = true;
        }


    }

    private void LoadData(string CustID)
    {
        CustBLL bllc = new CustBLL(DbConnectionStr);
        Label2.Text = bllc.GetCustName(CustID);

        if (Request.QueryString["CustMettingID"] != null)
        {
            CustMettingID.Text = Request.QueryString["CustMettingID"].ToString();
            loadCustFollow(CustMettingID.Text);
        }

    }

    private void loadCustFollow(string CustMettingID)
    {
        Ylh.BLL.CustMettingBLL bllm = new CustMettingBLL(DbConnectionStr);
        Ylh.Model.TbCustMetting model = bllm.GetModel(Convert.ToInt32(CustMettingID));
        MetingTime.SelectedDate = Convert.ToDateTime(model.MetingTime);
        Accompany.Text = model.Accompany;
        Remark.Text = model.Remark;


    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Ylh.Model.TbCustMetting model = GetMetInfo();

        CustMettingBLL bllc = new CustMettingBLL(DbConnectionStr);

        if (string.IsNullOrEmpty(CustMettingID.Text))
        {
            CustMettingID.Text = bllc.InsertMettingInfo(model).ToString(); ;
            //Alert.Show("添加成功");
        }
        else
        {
            bllc.UpdateMettingInfo(model);
            //Alert.Show("修改成功");
        }

        PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());


    }

    private Ylh.Model.TbCustMetting GetMetInfo()
    {
        int CustID = int.Parse(Request.QueryString["CustID"]);
        int StaffID = int.Parse(base.StaffID.ToString());
        string Accompany = this.Accompany.Text;
        string Remark = this.Remark.Text;
        DateTime MetingTime = DateTime.Parse(this.MetingTime.Text);

        Ylh.Model.TbCustMetting model = new Ylh.Model.TbCustMetting();

        if (!string.IsNullOrEmpty(CustMettingID.Text))
        {
            model.CustMettingID = Convert.ToInt32(CustMettingID.Text);
        }


        model.CustID = CustID;
        model.StaffID = StaffID;
        model.Accompany = Accompany;
        model.Remark = Remark;
        model.MetingTime = MetingTime;
        return model;
    }

    protected void Accompany_TriggerClick(object sender, EventArgs e)
    {
        PageContext.RegisterStartupScript(Window1.GetSaveStateReference(TextBox1.ClientID, TextBox2.ClientID, Accompany.ClientID) + Window1.GetShowReference("../StaffManger/StaffTree.aspx", "选择员工"));
    }
}